<template>
	<view class="f28r col313131">
		<navbar background="background-image: linear-gradient(to right, #2c6739, #99c043);"
			title="我的邀请" back @onBack="goBack" @topTotalHeight="topTotalHeight"
		></navbar>
		<view class="disFlex teAliCenter lh88r backColWhite borB1SE6e6e6">
			<view :class="['flex1', 'poRel', timeStatus == 0 ? 'col99c043 foWeiBold' : ''
				]" @click="timeSwitch(0)"
			>
				全部
				<text class="poAbs left50P trTrXn50P bom0 backCol99c043 h6r w50r"
					v-show="timeStatus == 0"
				></text>
			</view>
			<view :class="['flex1', 'poRel', timeStatus == 1 ? 'col99c043 foWeiBold' : ''
				]" @click="timeSwitch(1)"
			>
				直接
				<text class="poAbs left50P trTrXn50P bom0 backCol99c043 h6r w50r"
					v-show="timeStatus == 1"
				></text>
			</view>
			<view :class="['flex1', 'poRel', timeStatus == 2 ? 'col99c043 foWeiBold' : ''
				]" @click="timeSwitch(2)"
			>
				间接
				<text class="poAbs left50P trTrXn50P bom0 backCol99c043 h6r w50r"
					v-show="timeStatus == 2"
				></text>
			</view>
		</view>
		<swiper @change="swiperChaFun" :current="timeStatus"
			:style="'min-height: ' + 'calc(100vh - ' + calcNum + 'px);'"
		>
			<swiper-item class="overYS">
				<scroll-view scroll-y="true" class="hPer100" @scrolltolower="orderScroll"
					:refresher-enabled="true" :refresher-triggered="data0Tri"
					@refresherrefresh="orderRefresh"
				>
					<partnerList :partnerData="data0List" :partnerMore="data0More"
					></partnerList>
				</scroll-view>
			</swiper-item>
			<swiper-item class="overYS">
				<scroll-view scroll-y="true" class="hPer100" @scrolltolower="orderScroll"
					:refresher-enabled="true" :refresher-triggered="data1Tri"
					@refresherrefresh="orderRefresh"
				>
					<partnerList :partnerData="data1List" :partnerMore="data1More"
					></partnerList>
				</scroll-view>
			</swiper-item>
			<swiper-item class="overYS">
				<scroll-view scroll-y="true" class="hPer100" @scrolltolower="orderScroll"
					:refresher-enabled="true" :refresher-triggered="data2Tri"
					@refresherrefresh="orderRefresh"
				>
					<partnerList :partnerData="data2List" :partnerMore="data2More"
					></partnerList>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>
<script>
import navbar from '@/components/navbar.vue'
import { getMyInviteList } from '@/utils/api.js'
import partnerList from '@/components/partnerList.vue'
export default {
	components: { navbar, partnerList },
	data() {
		return {
			calcNum: 0,
			timeStatus: 0,
			data0Tri: false, data0List: [], data0More: false, data0Page: 0,
			data1Tri: false, data1List: [], data1More: false, data1Page: 0,
			data2Tri: false, data2List: [], data2More: false, data2Page: 0,
		}
	},
	onLoad() {
		this.getDataList1(0, '');
		this.getDataList1(0, 1);
		this.getDataList1(0, 2);
	},
	methods: {
		goBack() {
			uni.navigateBack()
		},
		topTotalHeight(height) {
			// #ifdef MP-WEIXIN
				this.calcNum = height + 45;
			// #endif
			// #ifdef H5
				this.calcNum = 45;
			// #endif
		},
		timeSwitch(type) {
			if(this.timeStatus != type) {
				this.timeStatus = type;
			}
		},
		swiperChaFun(eee) {
			if (eee.detail.source == 'touch') {
				this.timeStatus = eee.detail.current;
			}
		},
		getDataList1(page, type, callBack) {
			// uni.showLoading({ title: '加载中...' })
			getMyInviteList({
				token: uni.getStorageSync('token'), number: 10,
				page, type
			}).then(res => {
				console.log(22, res)
				if(type == '') {
					if(page > 0) {
						this.data0List = this.data0List.concat(res.data.data);
					}else {
						this.data0List = res.data.data;
					}
					if(res.data.number < 10) this.data0More = true;
				}else if(type == 1) {
					if(page > 0) {
						this.data1List = this.data1List.concat(res.data.data);
					}else {
						this.data1List = res.data.data;
					}
					if(res.data.number < 10) this.data1More = true;
				}else if(type == 2) {
					if(page > 0) {
						this.data2List = this.data2List.concat(res.data.data);
					}else {
						this.data2List = res.data.data;
					}
					if(res.data.number < 10) this.data2More = true;
				}
				// uni.hideLoading();
				if(callBack) callBack();
			})
		},
		orderScroll() {
			if(this.timeStatus == 0) {
				if(!this.data0More) {
					this.data0Page += 1;
					this.getDataList1(this.data0Page, '');
				}
			}else if(this.timeStatus == 1) {
				if(!this.data1More) {
					this.data1Page += 1;
					this.getDataList1(this.data1Page, 1);
				}
			}else if(this.timeStatus == 2) {
				if(!this.data2More) {
					this.data2Page += 1;
					this.getDataList1(this.data2Page, 2);
				}
			}
		},
		orderRefresh() {
			if(this.timeStatus == 0) {
				if(!this.data0Tri) {
					this.data0Tri = true;
					this.data0More = false;
					this.data0Page = 0;
					this.getDataList1(0, '', () => {
						this.data0Tri = false;
					})
				}
			}else if(this.timeStatus == 1) {
				if(!this.data1Tri) {
					this.data1Tri = true;
					this.data1More = false;
					this.data1Page = 0;
					this.getDataList1(0, 1, () => {
						this.data1Tri = false;
					})
				}
			}else if(this.timeStatus == 2) {
				if(!this.data2Tri) {
					this.data2Tri = true;
					this.data2More = false;
					this.data2Page = 0;
					this.getDataList1(0, 2, () => {
						this.data2Tri = false;
					})
				}
			}
		}
	}
}
</script>
<style>
</style>